#include <bits/stdc++.h>
using namespace std;
string marks = "!()-.[].{}\\|;:'\",./?<>";
map<string,string> dicts;
int main() {
	int n; 
	cin >> n;
	for (int i=0; i<n; i++) {
		string s, t;
		cin >> s >> t;
		dicts.insert({s, t});
	}
	string sen;
	cin >> sen;
	string dst;
	string word;
	for (int i=0; i<sen.length(); i++) {
		if (string::npos == marks.find(sen[i])) {
			word += sen[i];
		} else {
			if (word != "") {
				auto it = dicts.find(word);
				if (it != dicts.end()) {
					dst += it->second;
				} else {
					dst += "UNK";
				}
			}
			
			dst += sen[i];
			word = "";
		}	
	}
	if (word != "") {
		auto it = dicts.find(word);
		if (it != dicts.end()) {
			dst += it->second;
		} else {
			dst += "UNK";
		}
	}
	cout << dst;
	
	return 0;
} 
